/**
 * @param {number[]} nums
 * @return {number[]}
 */
const sortedSquares = function(nums) {
    let frontPoint = 0, rearPoint = nums.length - 1, squareArrKey = rearPoint;
    const squaresArr = []
    while (rearPoint >= frontPoint) {
        const rearSquareValue = nums[rearPoint] * nums[rearPoint],
            frontSquareValue = nums[frontPoint] * nums[frontPoint]
        if(rearSquareValue > frontSquareValue) {
            squaresArr[squareArrKey--] = rearSquareValue
            rearPoint--
        } else {
            squaresArr[squareArrKey--] = frontSquareValue
            frontPoint++
        }
    }
    return squaresArr
};

const nums = [-7,-3,2,3,11]
console.log(sortedSquares(nums))